\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q: I'm trying to use the
\f1\fs24\fc1\cf1 pasteFont:
\f0\fs28\fc0\cf0 method of the Text object to extract font information from the Font Pasteboard. The trouble is, when I try to do this, I always get the default font information—Helvetica 12pt. What am I doing wrong?\
\i \
\i0 A: The solution is easy but perhaps not obvious. In order for the paste operation to have any effect, the Text object must contain a selection. It is not even strictly necessary that it contain any text. The following code illustrates the “low-pain” method of extracting font values from the Pasteboard. (The alternative “high-pain” method would involve parsing the rich text format from the Pasteboard):\
\
\
\f1\fs24\fc1\cf1 #import <appkit/Text.h>\
#import <appkit/Font.h>\
\
\
id font, myText;\
\
/* Allocate a temporary Text object */\
myText = [[Text alloc] init];\
\
/* It must allow multiple fonts -- i.e. rich text */\
[myText setMonoFont: NO];\
\
/* Stick in some text -- optional */\
[myText setText:"hello"];\
\
/* And select it -- any selection will do so long */\
/* as something is selected */\
[myText setSel:0 :1];\
\
/* pasteFont: will copy the font info from the Pasteboard\